﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace MPViz
{
    public partial class WizardForm : Form
    {
        public string retStr;

        public WizardForm()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            InputClassForm icf = new InputClassForm();
            if(icf.ShowDialog() == DialogResult.OK) {
                noun1ListBox.Items.Add(icf.retStr);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (noun1ListBox.SelectedIndex >= 0)
            {
                noun1ListBox.Items.RemoveAt(noun1ListBox.SelectedIndex);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            InputClassForm icf = new InputClassForm();
            if (icf.ShowDialog() == DialogResult.OK)
            {
                verbListBox.Items.Add(icf.retStr);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (verbListBox.SelectedIndex >= 0)
            {
                verbListBox.Items.RemoveAt(verbListBox.SelectedIndex);
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            InputClassForm icf = new InputClassForm();
            if (icf.ShowDialog() == DialogResult.OK)
            {
                mpnounListBox.Items.Add(icf.retStr);
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (mpnounListBox.SelectedIndex >= 0)
            {
                mpnounListBox.Items.RemoveAt(mpnounListBox.SelectedIndex);
            }
        }
        private void button9_Click(object sender, EventArgs e)
        {
            InputClassForm icf = new InputClassForm();
            if (icf.ShowDialog() == DialogResult.OK)
            {
                noun2ListBox.Items.Add(icf.retStr);
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (noun2ListBox.SelectedIndex >= 0)
            {
                noun2ListBox.Items.RemoveAt(noun2ListBox.SelectedIndex);
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            InputClassForm icf = new InputClassForm();
            if (icf.ShowDialog() == DialogResult.OK)
            {
                noun3ListBox.Items.Add(icf.retStr);
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (noun3ListBox.SelectedIndex >= 0)
            {
                noun3ListBox.Items.RemoveAt(noun3ListBox.SelectedIndex);
            }
        }

        private void okBtn_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            int cn = 0;

            int mpnoun = mpnounListBox.Items.Count;
            int verb = verbListBox.Items.Count;
            int noun1 = noun1ListBox.Items.Count;
            int noun2 = noun2ListBox.Items.Count;
            int noun3 = noun3ListBox.Items.Count;

            List<int> mpnounlist = new List<int>();
            List<int> applympnounlist = new List<int>();

            List<int> verblist = new List<int>();
            List<int> noun1list = new List<int>();
            List<int> noun2list = new List<int>();
            List<int> noun3list = new List<int>();

            foreach (string s in mpnounListBox.Items)
            {
                int i = s.Substring(1).IndexOf('\"');
                string name = s.Substring(1, i);
                sw.WriteLine("class {0} mp {1}", cn, s);
                sw.WriteLine("class {0} verb \"Apply {1}\"", cn+mpnoun, name.ToLower());
                sw.WriteLine("rel real {0} {1}", cn + mpnoun, cn);
                mpnounlist.Add(cn);
                applympnounlist.Add(cn + mpnoun);
                cn++;
            }
            cn += mpnoun;

            foreach (string s in verbListBox.Items)
            {
                sw.WriteLine("class {0} verb {1}", cn, s);
                verblist.Add(cn);
                cn++;
            }

            foreach (int i in applympnounlist)
                foreach (int j in verblist)
                {
                    sw.WriteLine("rel general {0} {1}", j, i);
                }

            foreach (string s in noun1ListBox.Items)
            {
                sw.WriteLine("class {0} noun {1}", cn, s);
                noun1list.Add(cn);
                cn++;
            }

            string type;
            string label;

            type = comboBox1.Text;
            label = textBox1.Text;
            if (label != "") label = "\"" + label + "\"";

            foreach (int i in verblist)
                foreach (int j in noun1list)
                {
                    sw.WriteLine("rel {0} {1} {2} {3}", type, i, j, label);
                }


            foreach (string s in noun2ListBox.Items)
            {
                sw.WriteLine("class {0} noun {1}", cn, s);
                noun2list.Add(cn);
                cn++;
            }

            type = comboBox2.Text;
            label = textBox2.Text;

            if (label != "") label = "\"" + label + "\"";

            foreach (int i in mpnounlist)
                foreach (int j in noun2list)
                {
                    sw.WriteLine("rel {0} {1} {2} {3}", type, i, j, label);
                }

            
            
            foreach (string s in noun3ListBox.Items)
            {
                sw.WriteLine("class {0} noun {1}", cn, s);
                noun3list.Add(cn);
                cn++;
            }

            type = comboBox3.Text;
            label = textBox3.Text;

            if (label != "") label = "\"" + label + "\"";

            foreach (int i in noun2list)
                foreach (int j in noun3list)
                {
                    sw.WriteLine("rel {0} {1} {2} {3}", type, i, j, label);
                }
            

            retStr = sw.ToString();
            DialogResult = DialogResult.OK;
            Close();
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            Dictionary<string, string> ins1 = new Dictionary<string, string>();
            ins1["1"] = "Enter MP nouns and MP verbs.";
            ins1["2"] = "Enter MP nouns, attributes, and MP verbs.";
            ins1["2A"] = "Enter MP nouns, attributes, nouns & attributes in an MP noun modifier, association relationships between MP nouns and nouns in an MP noun modifier, and MP verbs.";
            ins1["2B"] = "Enter MP nouns, attributes, nouns & attributes in an MP noun modifier, aggregation relationships between an MP noun and nouns in an MP noun modifier, and MP verbs";
            ins1["2C"] = "Enter MP nouns, attributes, nouns & attributes in an MP noun modifier, prepositional relationships between MP noun and nouns in an MP noun modifier, and MP verbs.";
            ins1["3"] = "Enter MP nouns, nouns in an MP noun modifier, prepositional relationships between MP nouns and nouns in an MP noun modifier, and MP verbs.";
            ins1["4"] = "Enter MP nouns, the 1st level nouns and the 2nd level nouns in an MP noun modifier, prepositional relationships between MP nouns and the 1st level nouns, association relationship between the 1st level nouns and 2nd level nouns, and MP verbs.";
            ins1["4A"] = "Enter MP nouns, the 1st (2nd and 3rd) level nouns in an MP noun modifier, prepositional relationships between MP nouns and the 1st level nouns, association relationships between the 1st level nouns and the 2nd level nouns, and prepositional relationships between the 2nd level nouns and 3rd level, and MP verbs.";
            ins1["4B"] = "Enter MP nouns, the 1st and 2nd level nouns in an MP noun modifier, prepositional relationships between MP nouns and the 1st level nouns, aggregation relationships between the 1st level nouns and the 2nd level nouns, and MP verbs.";
            ins1["5"] = "Enter MP nouns, nouns in an MP noun modifier, association relationships between MP nouns and nouns in an MP noun modifier, and MP verbs.";
            ins1["5A"] = "Enter MP nouns, the 1st and 2nd level nouns in an MP noun modifier,  association relationships between MP nouns and the 1st level nouns, prepositional relationships between the 1st level nouns and the 2nd level nouns, and MP verbs.";
            ins1["6"] = "Enter MP nouns, nouns in an MP noun modifier, aggregation relationships between MP nouns and nouns in an MP noun modifier, and MP verbs.";
            ins1["7"] = "Enter MP nouns, the 1st and 2nd level nouns in an MP noun modifier, dependency or association relationships between MP nouns and the 1st level nouns, association relationships between the 1st level nouns and the 2nd level nouns, and MP verbs.";
            ins1["8"] = "Enter MP nouns and MP verbs. Enter MP nouns and MP verbs in an MP verb modifier.  Enter transitive verb relationships between MP verbs and MP verbs in an MP verb modifier.";
            ins1["8A"] = "Enter MP nouns, nouns in an MP noun modifier, MP verbs, aggregation relationships between MP nouns and nouns in an MP noun modifier. Enter MP verbs, MP nouns in an MP verb modifier. Enter transitive verb relationships between MP verbs and MP verbs in an MP verb modifier.";
            ins1["8B"] = "Enter MP nouns and MP verbs. Enter nouns in an MP verb modifier and transitive verb relationships between MP verbs and nouns in an MP verb modifier.";
            ins1["8C"] = "Enter MP nouns, nouns in an MP noun modifier, aggregation relationships between MP nouns and nouns in an MP noun modifier, and MP verbs. Enter nouns in an MP verb modifier, and transitive verb relationships between MP verbs and nouns in an MP verb modifier.";
            ins1["8D"] = "Enter MP nouns, and MP verbs. Enter the 1st and 2nd level nouns in an MP verb modifier, transitive verb relationships between MP verbs and the 1st level nouns, association relationships between the 1st level nouns and the 2nd level nouns.";
            ins1["9"] = "Enter MP nouns and MP verbs. Enter MP nouns in an MP noun modifier and MP verbs in an MP noun modifier. Enter an aggregation relationship between MP nouns and MP nouns in an MP noun modifier.";
            ins1["9A"] = "Enter MP nouns and MP verbs. Enter MP nouns in an MP noun modifier and MP verbs in an MP noun modifier. Enter a prepostional relationship between MP noun and MP nouns in an MP noun modifier.";

            instruction1TextBox.Text = ins1[comboBox4.Text];
            
            switch (comboBox4.Text)
            {
                case "1":
                    comboBox2.Text = "";
                    comboBox3.Text = "";
                    break;
                case "2":
                    comboBox2.Text = "";
                    comboBox3.Text = "";
                    break;
                case "2A":
                    comboBox2.Text = "assoc";
                    comboBox3.Text = "";
                    break;
                case "2B":
                    comboBox2.Text = "aggre";
                    comboBox3.Text = "";
                    break;
                case "2C":
                    comboBox2.Text = "prep";
                    comboBox3.Text = "";
                    break;
                case "3":
                    comboBox2.Text = "prep";
                    comboBox3.Text = "";
                    break;
                case "4":
                    comboBox2.Text = "prep";
                    comboBox3.Text = "assoc";
                    break;
                case "4A":
                    comboBox2.Text = "prep";
                    comboBox3.Text = "assoc";
                    break;
                case "4B":
                    comboBox2.Text = "prep";
                    comboBox3.Text = "aggre";
                    break;
                case "5":
                    comboBox2.Text = "assoc";
                    comboBox3.Text = "";
                    break;
                case "5A":
                    comboBox2.Text = "assoc";
                    comboBox3.Text = "prep";
                    break;
                case "6":
                    comboBox2.Text = "aggre";
                    comboBox3.Text = "";
                    break;
                case "7":
                    comboBox2.Text = "depend";
                    comboBox3.Text = "assoc";
                    break;
                case "8":
                    comboBox2.Text = "";
                    comboBox3.Text = "";
                    break;
                case "8A":
                    comboBox2.Text = "aggre";
                    comboBox3.Text = "";
                    break;
                case "8B":
                    comboBox2.Text = "";
                    comboBox3.Text = "";
                    break;
                case "8C":
                    comboBox2.Text = "aggre";
                    comboBox3.Text = "";
                    break;
                case "8D":
                    comboBox2.Text = "";
                    comboBox3.Text = "";
                    break;
                case "9":
                    comboBox2.Text = "aggre";
                    comboBox3.Text = "";
                    break;
                case "9A":
                    comboBox2.Text = "prep";
                    comboBox3.Text = "";
                    break;
                default:
                    break;
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                instruction2TextBox.Text = "Enter nouns in an MP verb modifier, and dependency relationship between nouns in an MP verb modifier and MP verbs except Type 8 (8A, 8B, 8C, and 8D).";
                comboBox1.Text = "depend";

            }
            else
            {
                instruction2TextBox.Text = "";
                comboBox1.Text = "";
            }
        }
    }
}
